package com.bd.scm.dao.mapper.repairAttendance;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bd.scm.domain.dto.common.FailDto;
import com.bd.scm.domain.dto.leave.BdLeaveOrderSerachDto;
import com.bd.scm.domain.dto.leave.LeaveFailDto;
import com.bd.scm.domain.dto.repairAttendance.AddRepairBatchDto;
import com.bd.scm.domain.dto.repairAttendance.BdRepairAddendanceDto;
import com.bd.scm.domain.dto.repairAttendance.RepairDetailDto;
import com.bd.scm.domain.dto.repairAttendance.RepairErrorDto;
import com.bd.scm.domain.dto.user.UserOfLeaveBatchDto;
import com.bd.scm.domain.models.repairAttendance.BdRepairAttendance;
import com.bd.scm.domain.models.repairAttendance.RepairExport;
import com.bd.scm.domain.models.repairAttendance.RepairView;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * <p>
 * 补出勤 Mapper 接口
 * </p>BdRepairAttendanceMapper.xml
 *
 * @author Mason
 * @since 2019-12-16
 */
public interface BdRepairAttendanceMapper extends BaseMapper<BdRepairAttendance> {
    /**
     * 获取批量补出勤单列表.
     *
     * @param bdLeaveOrderSerachDto 条件
     * @return
     */
    IPage<BdRepairAddendanceDto> getRepairAttendanceList(Page<BdRepairAddendanceDto> page, BdLeaveOrderSerachDto
            bdLeaveOrderSerachDto);

    /**
     * 获取详单人员.
     *
     * @param bdLeaveOrderSerachDto 条件
     * @return
     */
    List<RepairDetailDto> getUsersOfOrder(BdLeaveOrderSerachDto bdLeaveOrderSerachDto);

    /**
     * 保存补出勤明细单(下班打卡).
     *
     * @param addRepairBatchDto 补出勤信息
     */
    List<FailDto> saveRepairDetail(@Param("repair") AddRepairBatchDto addRepairBatchDto);

    /**
     * 保存选择的人员到临时表.
     *
     * @param addRepairBatchDto
     */
    void insertUserOfRepairBatch(@Param("repair") AddRepairBatchDto addRepairBatchDto);

    /**
     * 保存选择的时间段.
     *
     * @param addRepairBatchDto
     */
    void insertTimeOfRepairBatch(@Param("repair") AddRepairBatchDto addRepairBatchDto);

    /**
     * 删除补出勤单.
     *
     * @param bdRepairAddendanceDtoList
     */
    void deleteRepair(@Param("bdRepairAddendanceDtoList") List<BdRepairAddendanceDto>
                              bdRepairAddendanceDtoList);

    /**
     * 删除补出勤单.
     *
     * @param bdRepairAddendanceDtoList
     */
    void deleteRepairOfKtJl(@Param("bdRepairAddendanceDtoList") List<BdRepairAddendanceDto>
                                    bdRepairAddendanceDtoList);

    /**
     * 导出
     *
     * @param bdLeaveOrderSerachDto
     * @return
     */
    List<RepairExport> exportRepair(@Param("param2") BdLeaveOrderSerachDto bdLeaveOrderSerachDto);

    /**
     * 删除补出勤单（调存储过程）.
     *
     * @param orderIds
     */
    List<RepairErrorDto> deleteRepairProc(@Param("orderIds") String orderIds, @Param("userId") Long userId);

    /**
     * 获取补出勤单明细中已封账的人员记录数.
     *
     * @param bdRepairAddendanceDto
     */
    Integer getFzCount(@Param("bdRepairAddendanceDto") BdRepairAddendanceDto bdRepairAddendanceDto);

    /**
     * 获取补出勤分页数据
     *
     * @param page
     * @param query
     * @return
     */
    IPage<BdRepairAddendanceDto> getListByPage(IPage<BdRepairAddendanceDto> page, @Param(Constants.WRAPPER) QueryWrapper<BdRepairAddendanceDto> query);

    /**
     * 根据查询条件获取记录数
     *
     * @return
     */
    Integer getQueryCount(@Param(Constants.WRAPPER) QueryWrapper<BdRepairAddendanceDto> query);

    /**
     * 获取补出勤分页数据
     *
     * @param bdLeaveOrderSerachDto
     * @return
     */
    List<BdRepairAddendanceDto> getListByPageFromStore(@Param("map") BdLeaveOrderSerachDto bdLeaveOrderSerachDto);

    /**
     * 根据单子ID修改单子状态和审批人
     *
     * @param orderId
     * @param status
     * @param approver
     * @param remark
     */
    void updateApproverInfo(@Param("orderId") String orderId,
                            @Param("status") Integer status,
                            @Param("approver") String approver,
                            @Param("remark") String remark);

    /**
     * 审批通过后生成打卡记录、重新计算考勤
     *
     * @param orderId
     */
    void doAfterApprove(@Param("orderId") Integer orderId, @Param("status") int status);

    /**
     * 获取补出勤导出数据
     *
     * @param query
     * @return
     */
    List<RepairView> getExportListByPage(@Param("query") BdLeaveOrderSerachDto query);
}
